package com.dt76.smallloanbackendservice.controller.etao;

import com.dt76.smallloanbackendservice.pojo.etao.CurrentUser;
import com.dt76.smallloanbackendservice.pojo.etao.Employee;
import com.dt76.smallloanbackendservice.service.etao.EmployeeService;
import com.dt76.smallloanbackendservice.utils.Page;
import com.dt76.smallloanbackendservice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/getPageEmp")
    @ResponseBody
    public Page getPageEmp(@RequestParam String empName,
                           @RequestParam Integer dId,
                           @RequestParam Integer pageIndex) {
        return employeeService.getPageEmp(empName, dId, pageIndex);
    }
    @RequestMapping("/getAllEmp")
    @ResponseBody
    public List<Employee> getAllEmp() {
        return employeeService.getAllEmp();
    }

    @RequestMapping("/getEmpLoginName")
    @ResponseBody
    public Employee getEmpLoginName(@RequestParam String empLoginName) {
        return employeeService.getEmpByLoginName(empLoginName);
    }

    @RequestMapping("/updEmpEnable")
    @ResponseBody
    public Result updEmpEnable(@RequestParam Integer empId,
                        @RequestParam Integer updEnable) {
        Result result = new Result();
        result.setSuccess(employeeService.updEmpEnable(empId, updEnable));
        return result;
    }

    @RequestMapping("/getEmpById")
    @ResponseBody
    public Employee getEmpById(@RequestParam Integer eId) {
        return employeeService.getEmpById(eId);
    }
    @RequestMapping("/addEmp")
    @ResponseBody
    Result addEmp(@RequestBody Employee employee,@RequestParam Integer currentId) {
        Result result = new Result();
        result.setSuccess(employeeService.addEmp(employee,currentId));
        return result;
    }

    @RequestMapping("/updEmp")
    @ResponseBody
    public Result updEmp(@RequestBody Employee employee,@RequestParam Integer currentId) {
        Result result = new Result();
        result.setSuccess(employeeService.updEmp(employee,currentId));
        return result;
    }

    @RequestMapping("/delEmp")
    @ResponseBody
    public Result delEmp(@RequestParam Integer eId,@RequestBody CurrentUser currentUser) {
        Result result = new Result();
        result.setSuccess(employeeService.delEmp(eId,currentUser));
        return result;
    }


}
